'''
提供与mysql的连接，实现一些基本的操作
'''
import pymysql

class dbUtils():
    def __init__(self):
        self.conn=pymysql.connect(host="127.0.0.1",
                        user='cao',
                        passwd='cao123',
                        database='dbIdea',
                        charset='utf8')
        self.cursor = self.conn.cursor()

    def createTable(self,sql):
        # sql = "create table user(id int primary key auto_increment,username varchar(50),userpwd varchar(50))"
        self.cursor.execute(sql)
        self.conn.commit()

    def tableOperation(self,sql):
        flag = False
        try:
            self.cursor.execute(sql)
            self.conn.commit()
            flag = True
        except:
            flag = False
        return flag

    def queryTable(self,sql):
        self.cursor.execute(sql)
        res = self.cursor.fetchall()
        return res


if __name__=='__main__':
    d = dbUtils()
    sql = "insert into selfIntro values(null,'{}',{},'{}','{}',0)".format('admin',50,'篮球','现居住于星球，月亮陪伴')
    d.insertTable(sql)
    sql="select * from selfIntro"
    print(d.queryTable(sql))
